<?

$files= array_merge( glob( "*.js"), glob("*/*.js" ), glob("*/*/*.js" ) );
sort( $files );

$buffer= array( );
foreach( $files as $file ):
    #$buffer[]= "/* {$file} */\n";
    $buffer[]= preg_replace( '!\\s?\\{\\$(\\w*):[ \\t]*!e', ' " function( " . strtr( \'$1\', array( "_" => ", " ) ) . " ){ return " ', file_get_contents( $file ) ) . "\n\n";
endforeach;

header( 'Content-Type: text/javascript; charset=utf-8', true, 200 );

echo implode( "\n", $buffer );

?>